<div class="users get_application">
	<h2><?php echo __("Add Application by Template");?></h2>
	<table cellpadding="0" cellspacing="0">
		<tr>
			<th><?php echo __('id');?></th>
			<th><?php echo __('summary'); ?></th>
			<th><?php echo __('final_status');?></th>
			<th class="actions"><?php echo __('Actions'); ?></th>
		</tr>
<?php foreach ($templateList as $template): ?>
		<tr>
			<td><?php echo h($template['Application']['id']); ?>&nbsp;</td>
			<td><?php echo h($template['Application']['summary']); ?>&nbsp;</td>
			<td><?php echo h($template['Application']['final_status']); ?>&nbsp;</td>
			<td class="actions">
<?php 	echo $this->Form->postLink(__('Add Application'),
		array('action' => 'addApplication'), 
		array(
			'data' => array('template_id'=>$template['Application']['id'])
		),
		__('Do you really want to add application based on template# %s?', $template['Application']['id'])
	); 
?>
			</td>
		</tr>
<?php endforeach; ?>
	</table>
<?php echo $this->Form->create('Application');?>
	<h2><?php echo __('Add Template'); ?></h2>
<?php echo $this->Form->input('summary'); ?>
	<fieldset id="flownodes">
		<legend><?php echo __('Flownodes'); ?></legend>
		<div>
			<div style = "float:left; width:25%;clear: none;">
				<label>user_id</label>
				<input name="data[Flownode][0][user_id]" maxlength="20" type="text"/>
			</div>
			<div style = "float:left; width:25%;clear: none;">
				<label>loc_identity</label>
				<input name="data[Flownode][0][loc_identity]" maxlength="20" type="text"/>
			</div>
			<div style = "float:left; width:25%;clear: none;">
				<label>loc_index</label>
				<input name="data[Flownode][0][loc_index]" maxlength="20" type="text"/>
			</div>
		</div>
		<div>
			<div style = "float:left; width:25%;clear: none;">
				<label>user_id</label>
				<input name="data[Flownode][1][user_id]" maxlength="20" type="text"/>
			</div>
			<div style = "float:left; width:25%;clear: none;">
				<label>loc_identity</label>
				<input name="data[Flownode][1][loc_identity]" maxlength="20" type="text"/>
			</div>
			<div style = "float:left; width:25%;clear: none;">
				<label>loc_index</label>
				<input name="data[Flownode][1][loc_index]" maxlength="20" type="text"/>
			</div>
		</div>	
	</fieldset>
	<div>
		<a id="btnAddFlownode" href='#'>Add Flownode</a>
	</div>
<?php echo $this->Form->end(__('Submit'));?>

<script type="text/javascript">
	flownodeCount = 2;
	function addFlownode(val) {
		var div = document.createElement('div');
		
		var label = document.createElement('label');
		label.innerHTML = val;
		
		var input = document.createElement('input');
		input.name = 'data[Flownode][' + flownodeCount + '][' + val +']';
		input.maxLength = '20';
		input.type = 'text';
		
		div.appendChild(label);
		div.appendChild(input);
		div.style.float = 'left';
		div.style.width = '25%';
		div.style.clear = 'none';
		return div;
	}
	document.getElementById('btnAddFlownode').onclick = function() {
		var flownode = document.createElement('div');
		var flownodeUser = addFlownode('user_id');
		var flownodeIdentity = addFlownode('loc_identity');
		var flownodeIndex = addFlownode('loc_index');
		flownode.appendChild(flownodeUser);
		flownode.appendChild(flownodeIdentity);
		flownode.appendChild(flownodeIndex);
		document.getElementById('flownodes').appendChild(flownode);
		++flownodeCount;
		return false;
	}
</script>
</div>

